package com.heima.comment.controller.v1;

import com.heima.comment.service.MongoDbService;
import com.heima.model.comment.dtos.CommentDto;
import com.heima.model.comment.dtos.CommentLikeDto;
import com.heima.model.comment.dtos.CommentSaveDto;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: xrl
 * @Date: 2022/10/21  16:43
 * @Version 1.0
 */
@RestController
@RequestMapping("/api/v1/comment")
public class CommentController {

    @Autowired
    private MongoDbService mongoDbService;

    /**
     * 保存评论
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CommentSaveDto dto) {
        return mongoDbService.saveComment(dto);
    }

    /**
     * 查询评论列表
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody CommentDto dto) {
        return mongoDbService.getComment(dto);
    }

    /**
     * 点赞
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody CommentLikeDto dto) {
        return mongoDbService.likeComment(dto);
    }
}
